package com.atguigu.educms.service.impl;

import com.atguigu.commonutils.result.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.educms.entity.Banner;
import com.atguigu.educms.service.BannerService;
import com.atguigu.educms.mapper.BannerMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author kabuda
* @description 针对表【crm_banner(首页banner表)】的数据库操作Service实现
* @createDate 2023-05-11 19:55:32
*/
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner>
    implements BannerService {

    @Override
    public R pageList(Long page, Long limit) {
        Page<Banner> page1 = new Page<Banner>(page,limit);
        //降序
        LambdaQueryWrapper<Banner> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Banner::getId);
        IPage<Banner> iPage = this.page(page1, wrapper);
        return R.ok().data("list",iPage.getRecords()).data("total",iPage.getTotal());
    }


    @Cacheable(value = "banner",key = "'bannerList'")
    @Override
    public List<Banner> bannerList() {
        LambdaQueryWrapper<Banner> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Banner::getId);
        wrapper.last("limit 2");
        List<Banner> list = this.list(wrapper);
        return list;
    }
}




